<?php  
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Layout {
	private $obj;
	private $layout;
	private $layout_title;
   
	public function __construct($layout = "default"){
		$this->obj =& get_instance();
		$this->layout = $layout;
	}
	public function setTitle($title){
		$this->layout_title = $title;
	}
	public function setLayout($layout){
		$this->layout = $layout;
	}

	public function view($view, $data=null, $return=false){
		$loadedData['page_title'] = $this->layout_title;
		$data['base_url'] = $loadedData['base_url'] = $this->obj->config->item('base_url');
		$data['static_url'] = $loadedData['static_url'] = $this->obj->config->item('base_url').'/statics/'.THEME_DIR.'/';
		$data['currentUser'] = $this->obj->session->userdata('user_name');
		$loadedData['page_content'] = $this->obj->load->view($view,$data,true);
		
		if($return):
			$output = $this->obj->load->view('layouts/'.$this->layout, $loadedData, true);
		return $output;
		else:
			$this->obj->load->view('layouts/'.$this->layout, $loadedData, false);
		endif;
	}
   
}